home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / win / afxvbx.zip / AFXVBX.CPP < prev    next >
C/C++ Source or Header  |  1993-06-15  |  6KB  |  134 lines

  1. /*------------------------------------------------------------------------------* 
  2.  |                                                                              |
  3.  |                          File Name: AFXVBX.CPP                               |
  4.  |                                                                              |
  5.  | Description:  This file contains all the functions for the AFXDLL used by    |
  6.  |               its calling application APP.EXE                                |
  7.  |                                                                              |
  8.  | History:      Date              Author                Comment                |
  9.  |             05/23/93      Pran Punniamoorthy          Created with the help  |
  10.  |                                                       of John Seghers        |
  11.  |                                                                              |
  12.  *------------------------------------------------------------------------------*/
  13. #include <afxwin.h>
  14. #include <afxext.h>
  15. #include <afxdllx.h>    // standard MFC Extension DLL routines 
  16. #include "afxdllres.h"   // The DLL resource definitions
  17. #include "afxvbx.h"     // The DLL class definitions
  18.  
  19. HINSTANCE hInstDLL;     // Global copy of the DLL instance handle
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // Initialization of MFC Extension DLL
  23.  
  24. static AFX_EXTENSION_MODULE NEAR extensionDLL = { NULL, NULL };
  25.  
  26. extern "C" int CALLBACK LibMain(HINSTANCE hInstance, WORD, WORD, LPSTR)
  27. {
  28.     // Extension DLL one-time initialization - do not allocate memory here,
  29.     //   use the TRACE or ASSERT macros or call MessageBox
  30.  
  31.     AfxInitExtensionModule(extensionDLL, hInstance);
  32.     hInstDLL = hInstance;
  33.     return 1;   
  34. }
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Exported DLL initialization is run in context of running application      
  38.  
  39. extern "C" extern void _export WINAPI InitAfxVbx()
  40. {
  41.     new CDynLinkLibrary(extensionDLL);
  42.  
  43.     CWinApp* pApp = AfxGetApp(); 
  44.     ASSERT(pApp != NULL);
  45.     
  46.     pApp->m_pMainWnd = new CMainWindow();           // Create MainWindow object
  47.     pApp->m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
  48.     pApp->m_pMainWnd->UpdateWindow();   
  49.     
  50.     WNDCLASS wndClass;
  51.     
  52.     if(::GetClassInfo(hInstDLL,"VBControl",&wndClass)==0) // Get the wndclass struct. of class VBControl
  53.       {
  54.       VERIFY(::GetClassInfo(AfxGetInstanceHandle(),"VBControl",&wndClass)); 
  55.       wndClass.hInstance = hInstDLL; // Change the instance handle so it is that of the DLL and not the App.
  56.       VERIFY(::RegisterClass(&wndClass));  // Register the class
  57.       }
  58.       
  59. }
  60.  
  61.  
  62. /*------------------------------------------------------------------------------*
  63.  |                       Constructor For class CMainWindow                      |
  64.  |                                                                              |
  65.  | Description:  In the constructor, the main window for the application is     |
  66.  |               created.                                                       |
  67.  |                                                                              |
  68.  | Parameters :  none                                                           |
  69.  |                                                                              |
  70.  | Returns    :  void                                                           |
  71.  |                                                                              |
  72.  *------------------------------------------------------------------------------*/
  73.  
  74. CMainWindow::CMainWindow()
  75.     Create( NULL, "VBX Control resource of AFXDLL",
  76.         WS_OVERLAPPEDWINDOW, rectDefault, NULL, MAKEINTRESOURCE(IDR_MENU1) );    
  77. }
  78.  
  79. /*------------------------------------------------------------------------------*
  80.  |                       CMainWindow::OnVBXDialog()                             |
  81.  |                                                                              |
  82.  | Description:  This function displays a dialog box that contains a vbx control|
  83.  |               which is a resource of the DLL.                                |
  84.  |                                                                              |
  85.  | Parameters :  none                                                           |
  86.  |                                                                              |
  87.  | Returns    :  void                                                           |
  88.  |                                                                              |
  89.  *------------------------------------------------------------------------------*/
  90.  
  91. void CMainWindow::OnVBXDialog()
  92. {
  93.     CVBXDialog vbxDialog(IDD_DIALOG1);
  94.     vbxDialog.DoModal();
  95. }
  96.  
  97.  
  98.  
  99. ////////////////////////////// The Message Map for class CMainWindow /////////////////////////
  100.  
  101. BEGIN_MESSAGE_MAP( CMainWindow, CFrameWnd )
  102.     ON_COMMAND( ID_DIALOG_DIALOGPRESS, OnVBXDialog )
  103. END_MESSAGE_MAP()              
  104.  
  105.  
  106. /*------------------------------------------------------------------------------*
  107.  |                       CVBXDialog::OnInitDialog()                             |
  108.  |                                                                              |
  109.  | Description:  This function does the necessary function calls to get a vbx   |
  110.  |               control that is part of a dialog that is a resource of a AFXDLL|
  111.  |               to be displayed correctly.  Add your own initialization code   |
  112.  |               below the comment line "Add your initialization code below".   |
  113.  |                                                                              |
  114.  | Parameters :  none                                                           |
  115.  |                                                                              |
  116.  | Returns    :  BOOL                                                           |
  117.  |                                                                              |
  118.  *------------------------------------------------------------------------------*/
  119.  
  120. BOOL CVBXDialog::OnInitDialog()
  121. {
  122.     HINSTANCE hOldInstance = _AfxGetAppData()->appCurrentInstanceHandle;
  123.     _AfxGetAppData()->appCurrentInstanceHandle = hInstDLL;
  124.     CDialog::OnInitDialog();
  125.     _AfxGetAppData()->appCurrentInstanceHandle = hOldInstance;
  126.  
  127.     // Add your initialization code below
  128.     
  129.     return TRUE;
  130. }
  131.   
  132.   
  133.